$().ready(function() {
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		update();
	}
});
function update() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/usabb/maternityCombosCategory/update",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			name : {
				required : true
			}
		},
		messages : {
			name : {
				required : icon + "请输入名字"
			}
		}
	})
}


//新增row
function appendRow(currentTable) {
    var pureRow = "<tr>\n" +
        "  <td>\n" +
        "      <input name=\"itemNo\" class=\"form-control\" type=\"text\">\n" +
        "  </td>\n" +
        "  <td>\n" +
        "      <input name=\"itemName\" class=\"form-control\" type=\"text\">\n" +
        "  </td>\n" +
        "  <td>\n" +
        "      <input name=\"itemRemark\" class=\"form-control\" type=\"text\">\n" +
        "  </td>\n" +
        "  <td>\n" +
        "      <input name=\"itemIntro\" class=\"form-control\" type=\"text\">\n" +
        "  </td>\n" +
        "  <td>\n" +
        "      \n" +
        "  </td>\n" +
        "  <td>\n" +
        "      <button type=\"button\" class=\"btn btn-danger\" onclick=\"removeRow(this)\">删除</button> \n" +
        "  </td>\n" +
        "</tr>";

    $('.itemId_' + currentTable).append(pureRow);
    //$(obj).parents("tbody").append(pureRow);
    //console.log('new row. cateCounter:', cateCounter);
}


function removeRow(obj) {
    $(obj).parents("tr").remove();
    console.log('remove row done.');

}
